package com.hna.eking.AirlineServer.Platform.Common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.hna.eking.AirlineServer.Platform.FileUpload.FileUploadInterceptor;

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //super.addInterceptors(registry);
        //拦截所有请求
        registry.addInterceptor(new FileUploadInterceptor()).addPathPatterns("/file/upload");
    }
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //将所有/static/** 访问都映射到classpath:/static/ 目录下
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
    
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//           registry.addMapping("/mapinfo/mapinfolist")
//           .allowedOrigins("http://192.168.3.58")
//           .allowedMethods("GET", "POST")
//           .allowCredentials(false).maxAge(3600);
//    }
    
    public void addCorsMappings(CorsRegistry registry) {
    	registry.addMapping("/**").allowedHeaders("Authorization").exposedHeaders("Authorization").allowCredentials(true).allowedMethods("GET", "POST")
//    	registry.addMapping("/**").allowedMethods("GET", "POST")
        	.allowedOrigins("http://localhost:8081","http://localhost:8089", "http://192.168.3.49:8080", "http://192.168.3.68:8080","http://mgr.aivac.com:8081","http://192.168.3.52:8081");
    }
}
